package managedbean.Employee;

import entity.Employee;
import entity.Position;
import entity.Role;
import java.io.Serializable;
import java.util.List;
import javax.ejb.EJB;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.faces.event.PhaseEvent;
import session.stateless.EmployeeBeanLocal;

@ManagedBean(name="deleteEmployeeManagerBean")
@ViewScoped
public class DeleteEmployeeManagerBean implements Serializable
{
    @EJB
    private EmployeeBeanLocal employeeBeanLocal;
    
    private Employee employeeToDelete;
    private String statusMessage;

    public Employee getEmployeeToDelete() {
        return employeeToDelete;
    }

    public void setEmployeeToDelete(Employee employeeToDelete) {
        this.employeeToDelete = employeeToDelete;
    }    
    
    public DeleteEmployeeManagerBean() {}
    
    public void initView(PhaseEvent event){
        if (employeeToDelete == null)
        {
            employeeToDelete = (Employee) FacesContext.getCurrentInstance().getExternalContext().getFlash().get("selectedEmployee");
        }
    }
    
    public void deleteEmployee(ActionEvent event)
    {
        employeeBeanLocal.deleteEmployee(employeeToDelete.getEmployeeId());
        statusMessage = "Delete employee " + employeeToDelete.getUserName() + " successfully"; 
 
        FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO,  "Delete Employee Result: " +statusMessage + "", "")); 
    }   
    
}
